import { Pipe, PipeTransform } from '@angular/core';

import { asString } from 'date-format';
import { isNumber, isString } from 'lodash';

@Pipe({
  name: 'timeFormat'
})
export class TimeFormatPipe implements PipeTransform {
  transform(value: any, ...args: unknown[]): unknown {
    if (isString(value)) {
      return (value as string).replace('T', ' ');
    }

    if (isNumber(value)) {
      if (value < 200000800000) {
        return asString('yyy-MM-dd hh:mm:ss', new Date(value * 1000));
      }

      return asString('yyy-MM-dd hh:mm:ss', new Date(value));
    }

    return value;
  }
}
